package com.zsc.wxm.ysh.anjo.service.base.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * mq配置
 *
 * @author playmaker
 */
@Configuration
public class RabbitMqConfig {

    /**
     * 消息队列
     */
    public final static String ES_QUEUE = "es_queue";

    /**
     * 交换机
     */
    public final static String ES_EXCHANGE = "es_exchange";

    /**
     * 路由键
     */
    public final static String ES_BIND_KEY = "es_exchange";

    /**
     * 创建队列
     * @return Queue
     */
    @Bean
    public Queue queue(){
        return new Queue(ES_QUEUE);
    }


    /**
     * 创建交换机
     * @return DirectExchange
     */
    @Bean
    public DirectExchange exchange(){
        return new DirectExchange(ES_EXCHANGE);
    }

    /**
     * 绑定
     * @return Binding
     */
    @Bean
    public Binding binding(){
        return BindingBuilder.bind(queue()).to(exchange()).with(ES_BIND_KEY);
    }
}
